﻿using System;
using Game.ExtensibleObjects;

namespace Game.Map.Extensions
{
    public static class FieldSelectExtensionHelper
    {
        public static FieldSelectExtension SelectedX(this IMapField map)
        {
            return map.Extensions.Find<FieldSelectExtension>();
        }

        public static FieldSelectExtension SelectedX(this IMapFieldView map)
        {
            return map.Extensions.Find<FieldSelectExtension>();
        }
    }

    public class FieldSelectExtension : IRuntimeExtension
    {
        public event EventHandler SelectedChanged;

        bool _Selected;

        public bool Selected
        {
            get { return _Selected; }
            set
            {
                _Selected = value;
                DoSelectedChanged();
            }
        }

        void DoSelectedChanged()
        {
            if (SelectedChanged != null)
            {
                var args = new EventArgs();
                SelectedChanged(this, args);
            }
        }

    }

    public class FieldSelectExtensionFactory : IRuntimeExtensionFactory
    {
        public IRuntimeExtension CreateExtension(IRuntimeExtensibleObject source)
        {
            return new FieldSelectExtension();
        }
    }
}
